package com.fuluwa.domain.shared;

import java.util.Date;

import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.fuluwa.infra.context.UserUtils;
import com.fuluwa.infra.exception.PersistenceException;

@MappedSuperclass
public abstract class AbstractIdMantainceDomainObject extends
		AbstractIdDomainObject {

	public AbstractIdMantainceDomainObject() {
		super();
	}

	public AbstractIdMantainceDomainObject(Long id) {
		super(id);
	}

	@Temporal(TemporalType.TIMESTAMP)
	protected Date addTime = new Date();

	@Temporal(TemporalType.TIMESTAMP)
	protected Date lastUpdateTime = new Date();

	protected String addUserName;

	@Override
	public void save() throws PersistenceException {
		addUserName = UserUtils.getCurrentUserName();
		super.save();
	}

	@Override
	public void update() throws PersistenceException {
		lastUpdateTime = new Date();
		super.update();
	}

	public Date getAddTime() {
		return addTime;
	}

	public Date getLastUpdateTime() {
		return lastUpdateTime;
	}

	public String getAddUserName() {
		return addUserName;
	}

}
